<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="销售价方案">
              <a-input placeholder="请输入销售价方案" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="12" :sm="24">
            <a-form-item label="公斤费">
              <a-input-number placeholder="请输入最小值" class="query-group-cust" v-model="queryParam.kiloFee_begin" :min="0" :precision="3" />
              <span class="query-group-split-cust"></span>
              <a-input-number placeholder="请输入最大值" class="query-group-cust" v-model="queryParam.kiloFee_end" :min="0" :precision="3" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="12" :sm="24">
            <a-form-item label="处理费">
              <a-input-number placeholder="请输入最小值" class="query-group-cust" v-model="queryParam.processFee_begin" :min="0" :precision="3" />
              <span class="query-group-split-cust"></span>
              <a-input-number placeholder="请输入最大值" class="query-group-cust" v-model="queryParam.processFee_end" :min="0" :precision="3" />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" v-has="'logisticsSalesPrice:add'">创建销售价</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" :preview="0"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <!-- 生效时间 -->
        <template slot="effectTimeSlot" slot-scope="text,record">
          <div class="templateSlot">
            <div v-if="record.effectBeginTime">
              <span>当前：</span>
              <span>{{record.effectBeginTime}}</span>
            </div>
            <div v-if="record.effectEndTime">
              <span>预设：</span>
              <span>{{record.effectEndTime}}</span>
            </div>
          </div>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'logisticsSalesPrice:edit'">编辑方案</a>

          <a-divider type="vertical" v-has="'logisticsSalesPrice:edit'" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item v-has="'logisticsSalesPrice:assignDepart'">
                <a @click="handleAssignCustomers(record)" >分配客户</a>
              </a-menu-item>
              <a-menu-item v-has="'logisticsSalesPrice:history'">
                <a @click="handleHistoricalPrice(record)" >历史价格</a>
              </a-menu-item>
              <!-- 操作日志 -->
              <a-menu-item>
                <j-operate-log v-model="record.id"></j-operate-log>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <logistics-sales-price-modal ref="modalForm" @ok="modalFormOk"></logistics-sales-price-modal>
    <!-- 分配客户 -->
    <logistics-assign-customers-modal ref="modalCustomersForm" @ok="modalFormOk"></logistics-assign-customers-modal>
    <!-- 历史价格 -->
    <logistics-historical-quotation-modal ref="modalHistoricalForm" @ok="modalFormOk"></logistics-historical-quotation-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import LogisticsSalesPriceModal from './modules/LogisticsSalesPriceModal'
  import LogisticsAssignCustomersModal from './modules/LogisticsAssignCustomersModal'
  import LogisticsHistoricalQuotationModal from './modules/LogisticsHistoricalQuotationModal'

  export default {
    name: 'LogisticsSalesPriceList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      LogisticsSalesPriceModal,
      LogisticsAssignCustomersModal,
      LogisticsHistoricalQuotationModal
    },
    data () {
      return {
        description: '物流销售价方案管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'销售价方案',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'公斤费',
            align:"center",
            dataIndex: 'kiloFee'
          },
          {
            title:'处理费',
            align:"center",
            dataIndex: 'processFee'
          },
          {
            title:'报价生效时间',
            align:"center",
            dataIndex: '',
            scopedSlots: { customRender: 'effectTimeSlot' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/logistics/sales/logisticsSalesPrice/list",
          delete: "/logistics/sales/logisticsSalesPrice/delete",
          deleteBatch: "/logistics/sales/logisticsSalesPrice/deleteBatch",
          exportXlsUrl: "/logistics/sales/logisticsSalesPrice/exportXls",
          importExcelUrl: "/logistics/sales/logisticsSalesPrice/importExcel",
        }
      }
    },
    methods: {
      handleHistoricalPrice(record){
        this.$refs.modalHistoricalForm.edit(record);
        this.$refs.modalHistoricalForm.title = "历史价格";
        this.$refs.modalHistoricalForm.disableSubmit = false;
      },
      handleAssignCustomers(record){
        this.$refs.modalCustomersForm.edit(record);
        this.$refs.modalCustomersForm.title = "分配客户";
        this.$refs.modalCustomersForm.disableSubmit = false;
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>